cap cd "/Users/kevincroke/Dropbox/UG Uwezo/Dataverse"

set more off
set varabbrev off

use "constructed_data/for_analysis", clear

*before running this do file, install the "esttab" ado file

*create macros
global outcomes "st_math st_english st_total"
global attend "inschool neverenrolled"
global controls "i.age##i.rd##female"
global balance "phone radio tv  water electricity female age female_head mother_postprimary  private"

*******************************************
**Tables 1-9 
*******************************************

/*
Table 1: balance check 
1) regress each variable on treatment to check p values
2) regress all variables together on treatment to generate F test
3) tabulate to check treat and control means
*/

foreach y in $balance  {
reg `y' treat if study_parish==1 & age1_7==1, r cluster(parishcode1)
}

reg treat $balance  if study_parish==1 & age1_7==1, r cluster(parishcode1) 
tabstat $balance if study_parish==1 & age1_7==1, by(treat) stats(mean, n)

***********
***Table 2
***********

foreach var in $outcomes {
reg `var' treat if age1_7==1, robust cluster (parishcode1) 
est store `var'
reg `var' treat $controls if age1_7==1, robust cluster (parishcode1) 
est store `var'1
}
esttab st_math st_math1 st_english st_english1 st_total st_total1, ///
compress se scalars (N r2) starlevels(* .1 ** .05 *** .01) varlabels(_cons Constant) ///
keep(treat)  replace title("main specification")

***********
***Table 3
***********

*Table 3: are dewormed kids in school more? 
foreach y in $attend {
reg `y' treat if age1_7==1, robust cluster (parishcode1) 
est store `y'
reg `y' treat $controls if age1_7==1, robust cluster (parishcode1) 
est store `y'1
}
esttab inschool inschool1 neverenrolled neverenrolled1, ///
compress se scalars (N r2) starlevels(* .1 ** .05 *** .01) varlabels(_cons Constant) ///
keep(treat)  replace title("attendance")


***************************
*Table 4: gender interaction for learning outcomes
***************************

foreach var in $outcomes {
reg `var' treat_female treat female if age1_7==1, robust cluster (parishcode1) 
est store `var'
reg `var' treat_female treat female $controls if age1_7==1, robust cluster (parishcode1) 
est store `var'1
}
esttab st_math st_math1 st_english st_english1 st_total st_total1, ///
compress se scalars (N r2) starlevels(* .1 ** .05 *** .01) varlabels(_cons Constant) ///
keep(treat_female treat female)  replace title("female x treat")


*females alone 
foreach var in $outcomes {
reg `var' treat if age1_7==1 & female==1, robust cluster (parishcode1) 
est store `var'
reg `var' treat $controls if age1_7==1 & female==1, robust cluster (parishcode1) 
est store `var'1
}
esttab st_math st_math1 st_english st_english1 st_total st_total1, ///
compress se scalars (N r2) starlevels(* .1 ** .05 *** .01) varlabels(_cons Constant) ///
keep(treat)  replace title("female subsample")


******
*table 5: Poverty interaction
******

foreach var in $outcomes {
reg `var' treat_poor treat bottom_2_2015 if age1_7==1, robust cluster (parishcode1) 
est store `var'
reg `var' treat_poor treat bottom_2_2015 $controls if age1_7==1, robust cluster (parishcode1) 
est store `var'1
}
esttab st_math st_math1 st_english st_english1 st_total st_total1, ///
compress se scalars (N r2) starlevels(* .1 ** .05 *** .01) varlabels(_cons Constant) ///
keep(treat_poor treat bottom_2_2015)  replace title("low assets x treat")


*********
*table 6: years of program eligibility
*********

foreach var in $outcomes {
reg `var' treat_expose2_4 treat expose2_4, robust cluster (parishcode1) 
est store `var'
reg `var' treat_expose2_4 treat expose2_4 $controls, robust cluster (parishcode1) 
est store `var'1
}
esttab st_math st_math1 st_english st_english1 st_total st_total1, ///
compress se scalars (N r2) starlevels(* .1 ** .05 *** .01) varlabels(_cons Constant) ///
keep(treat_expose2_4 treat expose2_4)  replace title("high exposure x treat")



********************
*table 7
********************

*under 14 interaction
foreach var in $outcomes {
reg `var' treat_under14 treat under14 if age1_7==1, robust cluster (parishcode1) 
est store `var'
reg `var' treat_under14 treat under14  $controls if age1_7==1, robust cluster (parishcode1) 
est store `var'1
}
esttab st_math st_math1 st_english st_english1 st_total st_total1, ///
compress se scalars (N r2) starlevels(* .1 ** .05 *** .01) varlabels(_cons Constant) ///
keep(treat_under14 treat under14)  replace title("under 14 x treat")

*under 14 alone

foreach var in $outcomes {
reg `var'  treat if age1_7==1 & under14==1, robust cluster (parishcode1) 
est store `var'
reg `var' treat $controls if age1_7==1 & under14==1, robust cluster (parishcode1) 
est store `var'1
}
esttab st_math st_math1 st_english st_english1 st_total st_total1, ///
compress se scalars (N r2) starlevels(* .1 ** .05 *** .01) varlabels(_cons Constant) ///
keep(treat)  replace title("under 14 subsample")

******************
*Table 8: treatment interacted with number of treatment eligible kids in households
******************

foreach var in $outcomes {
reg `var' spillover_treat treat others_treated if age1_7==1, robust cluster (parishcode1) 
est store `var'
reg `var' spillover_treat treat others_treated $controls if age1_7==1, robust cluster (parishcode1) 
est store `var'1
}
esttab st_math st_math1 st_english st_english1 st_total st_total1, ///
compress se scalars (N r2) starlevels(* .1 ** .05 *** .01) varlabels(_cons Constant) ///
keep(spillover_treat treat others_treated)  replace title("others treated x treat")


*****************
*table 9: early exposure
*****************


*Table 9: treatment x age 1 start

foreach var in $outcomes {
reg `var' age1_treat start1 treat years_treated if age1_7==1, robust cluster (parishcode1) 
est store `var'
reg `var' age1_treat start1 treat $controls years_treated if age1_7==1, robust cluster (parishcode1) 
est store `var'1
}
esttab st_math st_math1 st_english st_english1 st_total st_total1, ///
compress se scalars (N r2) starlevels(* .1 ** .05 *** .01) varlabels(_cons Constant) ///
keep(age1_treat start1 treat)  replace title("early exposure x treat")

